home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-01 | 6.5 KB | 159 lines | [TEXT/MPS ] |
- {
- File: Synchronization.p
-
- Contains: Synchronization Interfaces
-
- Version: Technology: System 8
- Release: Universal Interfaces 3.0d3 on Copland DR1
-
- Copyright: © 1984-1996 by Apple Computer, Inc. All rights reserved.
-
- Bugs?: If you find a problem with this file, send the file and version
- information (from above) and the problem description to:
-
- Internet: apple.bugs@applelink.apple.com
- AppleLink: APPLE.BUGS
-
- }
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := 0}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT Synchronization;
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED __SYNCHRONIZATION__}
- {$SETC __SYNCHRONIZATION__ := 1}
-
- {$I+}
- {$SETC SynchronizationIncludes := UsingIncludes}
- {$SETC UsingIncludes := 1}
-
- {$IFC UNDEFINED __TYPES__}
- {$I Types.p}
- {$ENDC}
- {$IFC UNDEFINED __KERNEL__}
- {$I Kernel.p}
- {$ENDC}
-
- {$PUSH}
- {$ALIGN POWER}
- {$LibExport+}
-
- {$IFC FOR_SYSTEM8_PREEMPTIVE }
- { Note: Lock, ReadWriteLock, and CountingSemaphore data structures must be LONG WORD ALIGNED in memory! }
-
- TYPE
- LockPtr = ^Lock;
- Lock = RECORD
- theInfo: ARRAY [0..1] OF UInt32;
- END;
-
- ReadWriteLockPtr = ^ReadWriteLock;
- ReadWriteLock = RECORD
- theInfo: ARRAY [0..4] OF UInt32;
- END;
-
- CountingSemaphorePtr = ^CountingSemaphore;
- CountingSemaphore = RECORD
- theInfo: ARRAY [0..5] OF UInt32;
- END;
-
- LockOptions = OptionBits;
-
- CONST
- kLockDisablesSwis = $00000001; { disable software interrupts while locked }
- kLockAdjustsPriorities = $00000002; { lock prevents priority inversion }
- kLockDisablesCompletionRoutines = $00000004; { disable software interrupts and system 7 completion routines while locked }
-
-
- TYPE
- InterruptState = Ptr;
- {
- Simple lock routines
- Locks may be created with the kLockDisablesSwis and/or kLockDisablesCompletionRoutines options,
- but no others.
- }
- FUNCTION CreateLock(VAR theLock: Lock; theOptions: LockOptions): OSStatus; C;
- FUNCTION DeleteLock(VAR theLock: Lock): OSStatus; C;
- FUNCTION BeginLockedSection(VAR theLock: Lock): OSStatus; C;
- FUNCTION TryBeginLockedSection(VAR theLock: Lock): OSStatus; C;
- FUNCTION EndLockedSection(VAR theLock: Lock): OSStatus; C;
- FUNCTION IsLockedSectionHeld(VAR theLock: Lock): BOOLEAN; C;
- {
- Reader/writer lock routines
- ReadWriteLocks may be created with the kLockDisablesSwis, kLockDisablesCompletionRoutines,
- and/or kLockAdjustsPriorities options.
- }
- FUNCTION CreateReadWriteLock(VAR theReadWriteLock: ReadWriteLock; theOptions: LockOptions): OSStatus; C;
- FUNCTION DeleteReadWriteLock(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION BeginReadLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION TryBeginReadLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION EndReadLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION BeginWriteLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION TryBeginWriteLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION EndWriteLockedSection(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION ChangeWriteLockToReadLock(VAR theReadWriteLock: ReadWriteLock): OSStatus; C;
- FUNCTION IsReadLockedSectionHeld(VAR theReadWriteLock: ReadWriteLock): BOOLEAN; C;
- FUNCTION IsWriteLockedSectionHeld(VAR theReadWriteLock: ReadWriteLock): BOOLEAN; C;
- FUNCTION GetReadWriteLockReaderCount(VAR theReadWriteLock: ReadWriteLock): ItemCount; C;
- FUNCTION GetReadWriteLockWriterID(VAR theReadWriteLock: ReadWriteLock): TaskID; C;
- {
- Counting semaphore routines
- CountingSemaphores currently have no options.
- }
- FUNCTION CreateCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore; theOptions: LockOptions; initialCount: SInt32; maximumCount: SInt32): OSStatus; C;
- FUNCTION DeleteCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore): OSStatus; C;
- FUNCTION WaitForCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore): OSStatus; C;
- FUNCTION SignalCountingSemaphore(VAR theCountingSemaphore: CountingSemaphore): OSStatus; C;
- FUNCTION GetCountingSemaphoreCount(VAR theCountingSemaphore: CountingSemaphore): SInt32; C;
- FUNCTION GetCountingSemaphoreMaxCount(VAR theCountingSemaphore: CountingSemaphore): SInt32; C;
- FUNCTION GetCountingSemaphoreWaiterCount(VAR theCountingSemaphore: CountingSemaphore): ItemCount; C;
- {
- Interrupt enabling and disabling. ** MAY ONLY BE CALLED FROM PRIVILEGED CODE!!! **
- Use very sparingly.
- }
- FUNCTION DisableInterrupts: InterruptState; C;
- PROCEDURE RestoreInterrupts(theState: InterruptState); C;
- {
- Atomic operations on 8-, 16-, and 32-bit entities.
- ** OPERATIONS THAT CROSS WORD (32-BIT) BOUNDARIES WILL FAIL!!! **
- }
- FUNCTION CompareAndSwapAligned(oldValue: UInt32; newValue: UInt32; VAR theValue: UInt32): BOOLEAN; C;
- { Note: TestAndSet uses PPC bit ordering, zero is the high bit, and theBit ranges from 0 - FFFFFFFF. }
- FUNCTION TestAndSet(theBit: UInt32; VAR startAddress: UInt8): BOOLEAN; C;
- FUNCTION IncrementAtomic8(VAR value: SInt8): SInt8; C;
- FUNCTION DecrementAtomic8(VAR value: SInt8): SInt8; C;
- FUNCTION AddAtomic8(amount: SInt32; VAR value: SInt8): SInt8; C;
- FUNCTION BitAndAtomic8(mask: UInt32; VAR value: UInt8): ByteParameter; C;
- FUNCTION BitOrAtomic8(mask: UInt32; VAR value: UInt8): ByteParameter; C;
- FUNCTION BitXorAtomic8(mask: UInt32; VAR value: UInt8): ByteParameter; C;
- FUNCTION IncrementAtomic16Aligned(VAR theValue: SInt16): SInt16; C;
- FUNCTION DecrementAtomic16Aligned(VAR theValue: SInt16): SInt16; C;
- FUNCTION AddAtomic16Aligned(theAmount: SInt32; VAR theValue: SInt16): SInt16; C;
- FUNCTION BitAndAtomic16Aligned(theMask: UInt32; VAR theValue: UInt16): UInt16; C;
- FUNCTION BitOrAtomic16Aligned(theMask: UInt32; VAR theValue: UInt16): UInt16; C;
- FUNCTION BitXorAtomic16Aligned(theMask: UInt32; VAR theValue: UInt16): UInt16; C;
- FUNCTION IncrementAtomicAligned(VAR theValue: SInt32): SInt32; C;
- FUNCTION DecrementAtomicAligned(VAR theValue: SInt32): SInt32; C;
- FUNCTION AddAtomicAligned(theAmount: SInt32; VAR theValue: SInt32): SInt32; C;
- FUNCTION BitAndAtomicAligned(theMask: UInt32; VAR theValue: UInt32): UInt32; C;
- FUNCTION BitOrAtomicAligned(theMask: UInt32; VAR theValue: UInt32): UInt32; C;
- FUNCTION BitXorAtomicAligned(theMask: UInt32; VAR theValue: UInt32): UInt32; C;
- { Atomic primitives for singly linked list manipulation. }
- PROCEDURE PushListElementAtomic(theListHead: UNIV Ptr; theListElement: UNIV Ptr; theLinkOffset: UInt32); C;
- FUNCTION PopListElementAtomic(theListHead: UNIV Ptr; theLinkOffset: UInt32): Ptr; C;
- {$ENDC}
- {$ALIGN RESET}
- {$POP}
-
- {$SETC UsingIncludes := SynchronizationIncludes}
-
- {$ENDC} {__SYNCHRONIZATION__}
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-